package ahjava.p11other.gui;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Graphics;
import javax.swing.JFrame;
import java.awt.event.MouseMotionAdapter;
import java.awt.event.MouseEvent;
public class 鼠标画图 {
	private JFrame frame;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					鼠标画图 window = new 鼠标画图();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	public 鼠标画图() {
		initialize();
	}
	private void initialize() {
		frame = new JFrame();
		frame.getContentPane().addMouseMotionListener(new MouseMotionAdapter() {
			@Override
			public void mouseDragged(MouseEvent e) {
				// 获取Graphics对象（为组件创建一个图形上下文）
				Graphics g = frame.getGraphics();
				// 设置颜色
				g.setColor(Color.BLUE);
				// g.drawLine(0,0, e.getX(), e.getY());
				// 画矩形（长度3px，宽度3px）代替点
				g.fillRect(e.getX() + 7, e.getY() + 30, 3, 3);
			}
		});
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
